package ArrayList.work03;

import java.util.*;

/**
 * 3、利用面向对象的思想设计一个员工管理系统。要求属性有：员工号，员工姓名、工员年龄，员工工资。员
 * 完成下面的要求
 * 1) 创建一个ArrayList<Employee>，在ArrayList<Employee>中增加三个员工，基本信息如下：
 * 工号  姓名   年龄   工资
 * 1     zhangsan  18    3000
 * 2     lisi      25    3500
 * 3     wangwu   22     3200
 * 2) 在lisi之前插入一个员工，信息为：姓名：zhaoliu，年龄：24，工资3300
 * 3) 删除wangwu 的信息
 * 4) 利用for 循环遍历，打印List 中所有工人的信息
 * 5) 利用迭代遍历，对List 中所有的工人调用work 方法。
 * 6) 为Employee 类重写equals方法和hashCode()方法，当员工工号、员工姓名相等时候才返回true
 */
public class Employee {
    private int id;
    private String name;
    private int age;
    private double salary;

    public Employee() {
    }

    public Employee(int id, String name, int age, double salary) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }
    public void work(){
        System.out.println(this.getName() + "正在努力工作！");
    }
    @Override
    public boolean equals(Object o){
        if (this == o) return true;
        if (o == null || getClass() != o.getClass())return false;
        Employee employee = (Employee) o;
        return id == employee.id && Objects.equals(name,employee.name);
    }
    @Override
    public int hashCode(){
        return Objects.hash(id,name);
    }
    static List<Employee> employeeList = new LinkedList<>();
    static {
        employeeList.add(new Employee(01,"张三",22,5000));
        employeeList.add(new Employee(02,"李四",23,5500));
        employeeList.add(new Employee(03,"王二",21,6000));
        //插入员工
        employeeList.add(01,new Employee(04,"王五",23,5100));
        //删除王二
        employeeList.remove(03);
    }

    public static void main(String[] args) {
        System.out.println("工号\t姓名\t年龄\t工资");
        for (int i = 0; i < employeeList.size(); i++) {
            Employee employee = employeeList.get(i);
            System.out.println(employee.getId() + "\t" + employee.getName() + "\t" + employee.getAge() + "\t" + employee.getSalary());
        }
        System.out.println("**********************");
        Iterator<Employee> it = employeeList.iterator();
        while (it.hasNext()){
            Employee curr = it.next();
            curr.work();
        }
    }
}
